<?php
/**
 * @file
 * Returns the HTML for a single Drupal page.
 *
 * Complete documentation for this file is available online.
 * @see https://drupal.org/node/1728148
 */
global $theme_path;
?>

<?php print render( $page['navigation'] ); ?>

<div id="page">
	<?php print render( $page['help'] ); ?>

    <header class="header" id="header" role="banner">
        <div class="wrapper">

            <div class="menu-trigger"></div>
            <div class="search-trigger"></div>
            <div class="font-size-trigger"></div>
			<?php if ( $logo ): ?>
                <a href="<?php print $front_page; ?>" title="<?php print t( 'Home' ); ?>" rel="home" class="header__logo" id="logo">
                    <img src="<?php print $logo; ?>" alt="<?php print t( 'Home' ); ?>" class="header__logo-image"/>
                </a>
			<?php endif; ?>

			<?php print render( $page['header'] ); ?>

        </div>
    </header>

    <div id="main">
		<?php print $messages; ?>
		<?php print render( $page['highlighted'] ); ?>

		<?php if ( $title ): ?>
            <h1 class="page__title title element-invisible" id="page-title"><?php print $title; ?></h1>
		<?php endif; ?>

		<?php print $breadcrumb; ?>

        <div id="content" class="column region-content" role="main">
            <article class="app" data-nid="<?php echo $node->nid; ?>">

				<?php print bck_render_( 'ads-blog-1080x120' ); ?>

                <div class="wrapper">
                    <div class="article-inner">
						<?php print render( $title_prefix ); ?>
						<?php print render( $title_suffix ); ?>
						<?php print render( $tabs ); ?>
						<?php if ( $action_links ): ?>
                            <ul class="action-links"><?php print render( $action_links ); ?></ul>
						<?php endif; ?>


                        <!-- KELVIN'S HARDCODE FOR THEMING -->
                        <h2 class="node-title"><?php print $title; ?></h2>

                        <div class="article-top">
							<?php echo jessica_thm_author_author_section( $node ); ?>
                            <div class="article-share-amount">
								<?php if ( ! empty( $node->field_social_count ) ): ?>
                                    <strong><?php print $node->field_social_count['und'][0]['value']; ?></strong>
								<?php else: ?>
                                    <strong>0</strong>
								<?php endif; ?>SHARES
                            </div>
                            <div class="article-share-action">
                                <a href="#" class="article-share-close icon icon-cross"></a>
                                <a href="#" class="article-share-icon icon icon-facebook"></a>
                                <a href="#" class="article-share-icon icon icon-sina"></a>
                                <a href="#" class="article-share-icon icon icon-whatsapp"></a>
                                <a href="#" class="article-share-icon icon icon-pinterest"></a>
                                <a href="#" class="article-share-icon icon icon-email"></a>
                                <a href="#" class="article-share-toggle icon icon-share"></a>
                            </div>
                        </div>

						<?php
						print bck_render_( 'msw-profile-mobile' ); ?>
						<?php
						$page_contents1 = $page['content'];
						$total_fci      = isset( $page_contents1['system_main']['nodes'][ $node->nid ]['field_article_content']['#object']->field_article_content['und'] ) ? count( $page_contents1['system_main']['nodes'][ $node->nid ]['field_article_content']['#object']->field_article_content['und'] ) : 0;
						$total_tags     = isset( $page_contents1['system_main']['nodes'][ $node->nid ]['field_article_content']['#object']->field_tags['und'] ) ? count( $page_contents1['system_main']['nodes'][ $node->nid ]['field_article_content']['#object']->field_tags['und'] ) : 0;
						for ( $x = 0; $x < $total_fci; $x ++ ) {
							$page_contents = $page_contents1['system_main']['nodes'][ $node->nid ]['field_article_content'][ $x ]['entity']['field_collection_item'];
							foreach ( $page_contents as $field_collection ) {
								if ( isset( $field_collection['field_previous_article'] ) && ! empty( $field_collection['field_previous_article'] ) ) {
									$node_prev_item = field_get_items( 'field_collection_item', $field_collection['#entity'], 'field_previous_article' );
									$node_prev_id   = $node_prev_item[0]['target_id'];
								} else {
									$node_prev_id = jessica_fmt_prev_next_article_prev_nid();
								}
								if ( isset( $field_collection['field_next_article'] ) && ! empty( $field_collection['field_next_article'] ) ) {
									$node_next_item = field_get_items( 'field_collection_item', $field_collection['#entity'], 'field_next_article' );
									$node_next_id   = $node_next_item[0]['target_id'];
								} else {
									$node_next_id = jessica_fmt_prev_next_article_next_nid();
								}
								$node_prev_details = node_load( $node_prev_id );
								$node_next_details = node_load( $node_next_id );
								if ( isset( $field_collection['field_image'][0]['#item']['uri'] ) ): ?>
                                    <div class="field-image">
                                        <div class="field-image-inner">
                                            <img src="<?php print file_create_url( $field_collection['field_image'][0]['#item']['uri'] ); ?>" alt="<?php print $field_collection['field_image'][0]['#item']['alt']; ?>">
                                            <div class="article-image-caption"><?php print $field_collection['field_image'][0]['#item']['title']; ?></div>
                                        </div>
                                    </div>
								<?php endif; ?>
                                <div class="field-body">
									<?php print render( $field_collection['field_body'] ); ?>
									<?php print render( $field_collection['field_video'] ); ?>
									<?php print render( $field_collection['field_images'] ); ?>
                                </div>

                                <div class="article-suggestion">
                                    <?php if (!empty($node_prev_id)): ?>
                                    <a href="<?php print url( "node/$node_prev_id" ); ?>">
										<?php
										$prev_img_link = isset( $node_prev_details->field_thumbnail ) && isset( $node_prev_details->field_thumbnail['und'] ) && isset( $node_prev_details->field_thumbnail['und'][0] ) ? file_create_url( $node_prev_details->field_thumbnail['und'][0]['uri'] ) : '/' . $theme_path . '/images/articles/no-thumbnail.png';
										$next_img_link = isset( $node_next_details->field_thumbnail ) && isset( $node_next_details->field_thumbnail['und'] ) && isset( $node_next_details->field_thumbnail['und'][0] ) ? file_create_url( $node_next_details->field_thumbnail['und'][0]['uri'] ) : '/' . $theme_path . '/images/articles/no-thumbnail.png';
										?>
                                        <img src="<?php print $prev_img_link; ?>" alt="<?php print $node_prev_details->title; ?>">
                                        <p><?php print $node_prev_details->title; ?></p>
                                    </a>
                                    <?php endif; ?>
                                    <?php if (!empty($node_next_id)): ?>
                                    <a href="<?php print url( "node/$node_next_id" ); ?>">
                                        <img src="<?php print $next_img_link; ?>" alt="<?php print $node_prev_details->title; ?>">
                                        <p><?php print $node_next_details->title; ?></p>
                                    </a>
                                    <?php endif; ?>
                                </div>
							<?php }
						}
						if ( $total_tags > 0 ) {
							print '<div class="field-tags">';
							for ( $t = 0; $t < $total_tags; $t ++ ) {
								$tags_contents = $page_contents1['system_main']['nodes'][ $node->nid ]['field_tags'][ $t ];
								$tag_title     = $tags_contents['#title'];
								$tag_link      = $tags_contents['#href'];
								//kpr($tags_contents);
								print '<a href=" /' . $tag_link . '">' . $tag_title . '</a>';
							}
							print '</div>';
						}
						?>

						<?php print render( $page['sidebar_first'] ); ?>

						<?php // print _get_block( 'scmedia_fb_comment', 'facebook_comment' ); ?>

                        <div class="article-readmore">
                            <a href="#">Read More</a>
                        </div>
                    </div>

					<?php print render( $page['sidebar_second'] ); ?>

					<?php
					print bck_render_( 'ads-article-300x250' );
					print views_embed_view( 'related_article', 'block_2' );
					print views_embed_view( 'most_popular', 'block_2', $node->nid );
					print bck_render_( 'ads-article-300x600' );
					?>

					<!--
                    <div class="article-subscribe">
                        <?php //print render($page['mc_below_content']); ?>
                    </div>
					-->

					<?php //print render($page['content']); ?>
					<?php //print $feed_icons; ?>
                </div>
            </article>
            <div id="article-loading"></div>
        </div>
		<?php //print render($page['below_content']); ?>
		<?php print render( $page['bottom'] ); ?>
		<?php print render( $page['footer'] ); ?>
    </div>

</div>

<?php print render( $page['popup'] ); ?>
<?php print render( $page['overlay'] ); ?>
<?php print render( $page['hidden'] ); ?>
